#include "Log.hpp"
#include "reactor.hpp"
#include "listener.hpp"
#include "connection.hpp"
using namespace LogModule;

int main(int argc, char *argv[])
{

    ENABLE_CONSOLE_LOG();
    if (argc != 2)
    {
        LOG(LogLevel::ERROR) << "参数信息错误！";
        exit(ARG_ERR);
    }
    uint16_t local_port = std::stoi(argv[1]);
    reactor eserver;
    auto conn = std::make_shared<listener>(local_port);

    // 完成具体的工作模块，也有一个 listenSock
    // 我们要把listenSocket 封装为一个connection, 托管给 epollserver
    // auto conn = std::make_shared<connection>(listen.sockfd());
    // func_t f = std::bind(listener::accepter, &listen, conn, nullptr);
    // conn->initCB(f, nullptr, nullptr);

    // auto conn = factory::BuildConnection(listen.sockfd(), EPOLLIN | EPOLLET, [&listen]()
    //                                     { listen.accepter(); }, nullptr, nullptr);

    eserver.insertConnection(conn);
    eserver.loop();

    return 0;
}